import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class runTicket {
    public static <E> void main(String[] args) {
        BlockingQueue<String> mq = (BlockingQueue<String>) new LinkedBlockingQueue<E>();
        ExecutorService pool = Executors.newCachedThreadPool();
        int requestNum = (int)(Math.random()*500);
        System.out.println("需要处理购票信息"+requestNum+"条++++++++++++++");
        for(int i =0; i<requestNum;i++){
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    try{
                        String msg = Thread.currentThread().getId()+"-购票信息:xxx";
                        mq.put(msg);
                        Thread.sleep(5);
                        System.out.println(msg);
                    }catch (Exception e){
                        e.printStackTrace();

                    }

                }
            });
        }
        pool.shutdown();
        ExecutorService pool2 = Executors.newFixedThreadPool(8);
        while(true){
            pool2.execute(new Runnable() {
                @Override
                public void run() {
                    try{
                        String msg = (String) mq.take();
                        System.out.println("已经处理："+msg);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }

    }

//    private interface BlockingQue<T, E> extends Queue<E> {
//        void put(String msg) throws InterruptedException;
//        E take() throws InterruptedException;
//    }
}
